<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            text-decoration: none;
            list-style: none;
        }
        .box{
            width: 370px;
            height: 360px;
            border: 2px solid #3f3a3a;
            /* overflow: hidden; */
            position: relative;
        }
        .imglist{
            width: 1110px;
            height: 360px;
        }
        .imglist img{
            width: 370px;
            height: 360px;
        }
        .imglist li{
            float: left;
        }
        .prev{
            background: #ae9d9d;
            width: 30px;
            height: 40px;
            color: azure;
            text-align: center;
            line-height: 40px;
            position: absolute;
            left: 5px;
            top: 45%;
        }
        .next{
            background: #ae9d9d;
            width: 30px;
            height: 40px;
            color: azure;
            text-align: center;
            line-height: 40px;
            position: absolute;
            right: 5px;
            top: 45%;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul class="imglist">
            <li><img src="img/1.jpg" alt=""></li>
            <li><img src="img/2.jpg" alt=""></li>
            <li><img src="img/3.jpg" alt=""></li>
            
        </ul>
        <div class="prev">«</div>
        <div class="next">»</div>
    </div>
</body>
<script>
     /*let left = 0;
     let timer;
     run();
     function run(){
     if(left<=1110){
       left=0;
     }
        imglist.style.marginLeft = left +'px' ;
        left -=10;
        timer=setTimeout(run,10);
     }*/

    let eprev = document.querySelector('.prev');
    let enext = document.querySelector('.next');
    eprev.onclick = function(){
        alert("向前");
        let prevgo =Math.floor(-left / 370) - 1;
        if (prevgo == -1){
            prevgo =3;
        }
        imgchange(prevgo);
    }
    enext.onclick = function(){
        alert("下一张");
        let pnextgo =Math.floor(-left / 370) + 1;
        if (pnextgo == 4){
            pnextgo =0;
        }
        imgchange(pnextgo);
    }
    function imgchange(n){
        let it = -(n*370);
        imglist.style.marginLeft = it + "px";
        left = it;
    }
    // eprev.onclick =function(){
    //     let prevgo =Math.floor(-left / 370) - 1;
    //     if (prevgo == -1){
    //         prevgo =3;
    //     }
    //     imgchange(prevgo)
    // }*/
</script>
</html>